package mulot;

import level.Plateau;
import level.iMulot;
import level.iTexture;
import level.mulotPerso;
import outils.Direction;
import affichage.fabriqueTexture;


public class Perceur extends Mulot implements iMulot{

	private boolean etatMetier;
	
	public Perceur(int x, int y, mulotPerso deleg) {
		super(x, y, deleg);
		etatMetier=false;
	}
	
	public Perceur(iMulot m){
		super(m);
	}
	
	public void deplacer(Plateau p){
		applicationMetier(p);
		super.deplacer(p);
	}
	
	private void applicationMetier(Plateau p){
		int xMax = p.getPlateau().length;
		mulotPerso deleg = getDeleg();
		Direction d = getD();
		int x = getX();
		int y = getY();
		
		if(!etatMetier){
			if(x>0 && x<xMax-1 && !p.getPlateau()[x+d.getDx()][y].traversable() && p.getPlateau()[x+d.getDx()][y].destructible()){
				p.getPlateau()[x+d.getDx()][y]=fabriqueTexture.fabriquer(' ');
				etatMetier=true;
			}
		}
		else{
			if(x>0 && x<xMax-1 && !p.getPlateau()[x+d.getDx()][y].traversable() && p.getPlateau()[x+d.getDx()][y].destructible()){
				p.getPlateau()[x+d.getDx()][y]=fabriqueTexture.fabriquer(' ');
			}
			else{
				deleg.changerVersMulot(p);
			}			
		}
	}	

	public void afficher(iTexture[][] tab){
		Direction dOld = getdOld();
		mulotPerso deleg = getDeleg();
		int x = getX();
		int y = getY();
		
		tab[x][y] = fabriqueTexture.fabriquer('p', deleg.getI(),dOld);
	} 

	
}
